package com.example.vote.config;

import com.example.vote.utils.Constant;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * ClassName: LoginInterceptor
 * Package: com.example.vote.config
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-06-27
 * Time: 8:41
 */


public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断Session
        HttpSession session = request.getSession(false);
        if (session != null && session.getAttribute(Constant.USERINFO_SESSION_ADMIN) != null){
            //没有登录
            return true;
        }
        if (session != null && session.getAttribute(Constant.USERINFO_SESSION_KET) != null){
            return true;
        }

        return false;
    }
}
